﻿package mortal.common.swfPlayer
{
    import flash.geom.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.common.swfPlayer.frames.*;
    import mortal.game.scene3D.player.info.*;

    public class GPlayer extends BitmapPlayer
    {
        protected var _url:String;
        private var _currentDirection:int = -1;
        private var _currentAction:int = -1;
        private var _currentFrame:int = 0;
        private var _fireFrame:int = 2;
        private var _firePoint:Point;
        private var _isRealTimeUpdate:Boolean = false;
        private var _direction:int;
        private var _isloadComplete:Boolean = false;
        private var _isUpdateFrames:Boolean = true;
        private var _movieClipData:IMovieClipData;
        public var index:int;
        public var loadComplete:Function;

        public function GPlayer()
        {
            this._firePoint = new Point();
            return;
        }// end function

        public function get isloadComplete() : Boolean
        {
            return this._isloadComplete;
        }// end function

        public function set isloadComplete(param1:Boolean) : void
        {
            this._isloadComplete = param1;
            return;
        }// end function

        public function get firePoint() : Point
        {
            return this._firePoint;
        }// end function

        public function get fireFrame() : int
        {
            return this._fireFrame;
        }// end function

        public function set fireFrame(param1:int) : void
        {
            this._fireFrame = param1;
            return;
        }// end function

        public function get isRealTimeUpdate() : Boolean
        {
            return this._isRealTimeUpdate;
        }// end function

        public function set isRealTimeUpdate(param1:Boolean) : void
        {
            this._isRealTimeUpdate = param1;
            return;
        }// end function

        public function get currentAction() : int
        {
            return this._currentAction == -1 ? (ActionType.DefaultAction) : (this._currentAction);
        }// end function

        public function updateAction(param1:int) : void
        {
            this._currentAction = param1;
            return;
        }// end function

        public function set currentAction(param1:int) : void
        {
            if (this._currentAction != param1)
            {
                this._currentAction = param1;
                this._isUpdateFrames = true;
            }
            return;
        }// end function

        public function get currentDirection() : int
        {
            return this._currentDirection == -1 ? (DirectionType.DefaultDir) : (this._currentDirection);
        }// end function

        public function set currentDirection(param1:int) : void
        {
            if (param1 != this._currentDirection)
            {
                this._currentDirection = param1;
                this._isUpdateFrames = true;
            }
            return;
        }// end function

        public function get movieClipData() : IMovieClipData
        {
            return this._movieClipData;
        }// end function

        public function get url() : String
        {
            return this._url;
        }// end function

        public function load(param1:String, param2:ModelType, param3:IModelInfo, param4:int = 2) : void
        {
            this._url = param1;
            var _loc_5:* = ModelData.getData(param1);
            if (_loc_5 == null)
            {
                this._movieClipData = param2.getMovieClipData();
                this._movieClipData.modelInfo = param3;
                this._movieClipData.addReference();
                ModelData.addData(param1, this._movieClipData);
            }
            else
            {
                this._movieClipData = _loc_5;
                this._movieClipData.addReference();
            }
            this._movieClipData.loadPriority = param4;
            this._movieClipData.load(param1, this.onLoaded);
            return;
        }// end function

        protected function onLoaded(param1:SwfFrames) : void
        {
            if (param1)
            {
                this.fireFrame = param1.fireFrame;
            }
            this.onDataComplete();
            return;
        }// end function

        private function onDataComplete() : void
        {
            this._isloadComplete = true;
            if (this.loadComplete is Function)
            {
                this.loadComplete.call(null, this);
            }
            return;
        }// end function

        public function get actionConut() : int
        {
            if (this._movieClipData)
            {
                return this._movieClipData.actionConut;
            }
            return 0;
        }// end function

        public function updateFrame(param1:int, param2:int, param3:Boolean = true) : void
        {
            this.currentAction = param1;
            this.currentDirection = param2;
            if (param3)
            {
                this._isUpdateFrames = param3;
            }
            if (this._isUpdateFrames && this._movieClipData)
            {
                source = this._movieClipData.getFrames(param1, param2);
                this._isUpdateFrames = false;
            }
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            super.dispose(param1);
            clear();
            rotation = 0;
            if (this._movieClipData != null)
            {
                this._movieClipData.removeReference();
                this._movieClipData = null;
            }
            this._currentAction = -1;
            this._currentDirection = -1;
            this._isloadComplete = false;
            this.loadComplete = null;
            this._url = null;
            this._currentDirection = -1;
            this._currentAction = -1;
            this._currentFrame = 0;
            this._fireFrame = 2;
            this._firePoint = new Point();
            this._isRealTimeUpdate = false;
            this._direction = 0;
            this._isloadComplete = false;
            this._isUpdateFrames = true;
            this.index = 0;
            return;
        }// end function

    }
}
